import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_ohos/components/FoodDetail.dart';

class MTFoodItem extends StatelessWidget {
  const MTFoodItem({Key? key, required this.foodItem}) : super(key: key);

  final Map<String, dynamic> foodItem;

// 左侧结构
  Widget getLeft() {
    return Container(
      margin: EdgeInsets.all(10),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(5),
        child: Image.network(
          foodItem["picture"],
          width: 100,
          height: 100,
          fit: BoxFit.cover,
        ),
      ),
    );
  }
// 右侧结构

  Widget getRight() {
    return Expanded(
        child: Padding(
      padding: EdgeInsets.only(top: 10, bottom: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            foodItem["name"],
            style: TextStyle(
              fontWeight: FontWeight.w600,
              fontSize: 20,
            ),
          ),
          Text('月销量${foodItem["month_saled"]} ${foodItem["like_ratio_desc"]}',
              style: TextStyle(fontWeight: FontWeight.w500, fontSize: 14)),
          Text(foodItem["price"].toString(),
              style: TextStyle(
                  fontWeight: FontWeight.w600,
                  fontSize: 14,
                  color: Colors.amber))
          // Text(),
          // Text(),
          // Text(),
        ],
      ),
    ));
  }

  Widget getChild() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [getLeft(), getRight()],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        // 构建组件形式跳转
        // Navigator.push(context,
        //     MaterialPageRoute(builder: (BuildContext context) {
        //   return const FoodDetail();
        // }));
        Navigator.pushNamed(context, "/tabs");
      },
      child: getChild(),
    );
  }
}
